package com.iris.live.services.data.specifications;

import com.iris.live.services.data.models.*;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.JoinType;
import java.util.Date;

/**
 * Created by Xin on 7/8/2016.
 */
public class MarketSpecifications {

    public static Specification<Lsh活动表Model> isActionNameLike(String name) {
        return (root, query, cb) -> cb.like(root.get("活动名称"), "%" + name + "%");
    }

    public static Specification<Lsh活动表Model> isActionLevelEqual(String level) {
        return (root, query, cb) -> cb.equal(root.get("活动级别"), level);
    }

    public static Specification<Lsh活动表Model> isActionTypeEqual(String type) {
        return (root, query, cb) -> cb.equal(root.get("活动类型"), type);
    }

    public static Specification<Lsh活动表Model> isActionStartBefore(Date start) {
        return (root, query, cb) -> cb.lessThanOrEqualTo(root.get("开始日期"), start);
    }

    public static Specification<Lsh活动表Model> isActionEndAfter(Date end) {
        return (root, query, cb) -> cb.greaterThanOrEqualTo(root.get("结束日期"), end);
    }

    public static Specification<Lsh活动表Model> isActionIdEqual(int id) {
        return (root, query, cb) -> cb.equal(root.get("活动编号"), id);
    }

    public static Specification<Lsh活动表Model> isActionStatusValid() {
        return (root, query, cb) -> cb.notEqual(root.get("启用状态"), "已删除");
    }

    public static Specification<Lsh活动表Model> isActionCodeLike(String actionCode) {
        return (root, query, cb) -> cb.like(root.get("活动代码"), actionCode);
    }

    public static Specification<用户Model> isUserLicenseEqual(String license) {
        return (root, query, cb) -> cb.equal(root.get("许可"), license);
    }

    public static Specification<用户Model> isUserStatusValid() {
        return (root, query, cb) -> cb.notEqual(root.get("删除状态"), "已删除");
    }

    public static Specification<顾客记录汇总Model> isCustomerLogChannelEqual(String channel) {
        return (root, query, cb) -> cb.equal(root.get("顾客渠道"), channel);
    }

    public static Specification<Lsh导入名单Model> likeUserName导入名单(String userName) {
        return (root, query, cb) -> cb.like(root.get("顾客姓名"), "%" + userName + "%");
    }

    public static Specification<Lsh导入名单Model> likeUserPhone导入名单(String userPhone) {
        return (root, query, cb) -> cb.like(root.get("电话号码"), "%" + userPhone + "%");
    }

    public static Specification<Lsh导入名单Model> equalUserPhone导入名单(String userPhone) {
        return (root, query, cb) -> cb.equal(root.get("电话号码"),  userPhone );
    }

    public static Specification<Lsh导入名单Model> isSource导入名单(String source) {
        return (root, query, cb) -> cb.equal(root.get("来源"), source);
    }

    public static Specification<Lsh导入名单Model> isBookingsEndBefore导入名单(Date bookingDate) {
        return (root, query, cb) -> cb.lessThanOrEqualTo(root.get("下次跟进日期"), bookingDate);
    }

    public static Specification<Lsh导入名单Model> isBookingsEndAfter导入名单(Date bookingDate) {
        return (root, query, cb) -> cb.greaterThanOrEqualTo(root.get("下次跟进日期"), bookingDate);
    }

    public static Specification<Lsh导入名单Model> is车型车系Equal导入名单(String series) {
        return (root, query, cb) -> cb.equal(root.join("lsh车型Model", JoinType.LEFT).get("来源"), series);
    }

    public static Specification<Lsh导入名单Model> is车型车型Equal导入名单(String model) {
        return (root, query, cb) -> cb.equal(root.join("lsh车型Model", JoinType.LEFT).get("车型"), model);
    }

    public static Specification<Lsh集团消息Model> is消息车型Equal集团消息(int model) {
        return (root, query, cb) -> cb.equal(root.join("Lsh集团信息车型Model", JoinType.INNER).get("车型编号"), model);
    }

    public static Specification<Lsh集团消息Model> likeNameEqual集团消息(String model) {
        return (root, query, cb) -> cb.like(root.get("名称"), "%" + model + "%");
    }

    public static Specification<Lsh集团消息Model> isDepartmentEqual集团消息(String model) {
        return (root, query, cb) -> cb.equal(root.join("Lsh集团信息部门Model", JoinType.LEFT).get("推送部门"), model);
    }

    public static Specification<Lsh集团消息Model> isTypeEqual集团消息(String model) {
        return (root, query, cb) -> cb.equal(root.get("分类"), model);
    }

    public static Specification<Lsh集团消息Model> isDateEndBefore集团消息(Date startDate) {
        return (root, query, cb) -> cb.lessThanOrEqualTo(root.get("开始日期"), startDate);
    }

    public static Specification<Lsh集团消息Model> isDateEndAfter导入名单(Date endDate) {
        return (root, query, cb) -> cb.greaterThanOrEqualTo(root.get("结束日期"), endDate);
    }

    public static Specification<Lsh导入名单联系表Model> isInputID(int ID,String PERMIT ) {
        return (root, query, cb) -> cb.and(cb.equal(root.get("导入编号"), ID),cb.equal(root.get("许可"), PERMIT));
    }
}
